//
//  SearchView.m
//  宜居HD
//
//  Created by 张金国 on 16/4/26.
//  Copyright © 2016年 张金国. All rights reserved.
//

#import "SearchView.h"
#import "Masonry.h"

@interface SearchView ()

@property (nonatomic ,strong)UILabel *itemLabel;
@property (nonatomic ,strong)UITextField *textField;

@end
@implementation SearchView
#pragma mark - init Override
- (instancetype)initWithTitle:(NSString *)title titleFont:(UIFont *)titleFont cornerRadius:(CGFloat)cornerRadius backgroundColor:(UIColor *)backgroundColor {

    self = [super init];
    
    if (self) {
        UILabel *itemLabel = [[UILabel alloc]init];
        UITextField *textField = [[UITextField alloc]init];
        [self addSubview:itemLabel];
        [self addSubview:textField];
        
        itemLabel.textAlignment = NSTextAlignmentRight;
        itemLabel.text = title;
        itemLabel.font = titleFont;
        textField.layer.cornerRadius = cornerRadius;
//        textField.layer.masksToBounds = YES;
        textField.backgroundColor = backgroundColor;
        
        self.itemLabel = itemLabel;
        self.textField = textField;
        [self setupConstraints];
        
    }
    return self;
}

#pragma mark - Private
- (void)setupConstraints {
    [self.itemLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(5);
        make.left.equalTo(self);
        make.width.equalTo(@50);
        make.bottom.equalTo(self.mas_bottom).offset(-5);
    }];
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.left.equalTo(self.itemLabel.mas_right).offset(20);
        make.height.equalTo(self.mas_height);
        make.right.equalTo(self.mas_right);
    }];
}
#pragma mark - Getter
- (UILabel *)itemLabel {
    if (!_itemLabel) {
    _itemLabel = [[UILabel alloc]init];
    }
    return _itemLabel;
}

- (UITextField *)textField {
    if (!_textField) {
        _textField = [[UITextField alloc]init];
    }
    return _textField;
}

- (NSString *)text {
    if (_text) {
        _text = self.textField.text;
    }
    return _text;
}

@end
